home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / EDITFILE.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  167 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.8  $
  6. //
  7. // Definition of class TEditFile, a text edit which can find/replace and
  8. // read/write from/to a file.
  9. //----------------------------------------------------------------------------
  10. #if !defined(OWL_EDITFILE_H)
  11. #define OWL_EDITFILE_H
  12.  
  13. #if !defined(OWL_EDITSEAR_H)
  14. # include <owl/editsear.h>
  15. #endif
  16. #if !defined(OWL_OPENSAVE_H)
  17. # include <owl/opensave.h>
  18. #endif
  19. #include <owl/editfile.rh>
  20.  
  21. #if defined(BI_NAMESPACE)
  22. namespace OWL {
  23. #endif
  24.  
  25. // Generic definitions/compiler options (eg. alignment) preceeding the 
  26. // definition of classes
  27. #include <services/preclass.h>
  28.  
  29. //
  30. // class TEditFile
  31. // ~~~~~ ~~~~~~~~~
  32. class _OWLCLASS TEditFile : public TEditSearch {
  33.   public:
  34.     TEditFile(TWindow*        parent = 0,
  35.               int             id = 0,
  36.               const char far* text = 0,
  37.               int x = 0, int y = 0, int w = 0, int h = 0,
  38.               const char far* fileName = 0,
  39.               TModule*        module = 0);
  40.  
  41.     // NOTE: The following constructor, which aliases an Edit control created
  42.     //       from a dialog resource is 'unconventional' in that it expects
  43.     //       a TModule reference instead of the traditional 'TModule* = 0'.
  44.     //       This is, however, to avoid ambiguities between the two forms
  45.     //       of constructor. Since it is traditionally created as a child
  46.     //       of a TDialog-derived class, you can simply use the module of the
  47.     //       parent object. 
  48.     //       For example,
  49.     //             TMyDialog::TMyDialog(....) {
  50.     //                edit = new TEditFile(this, ID_EDIT1, *GetModule());
  51.     //             }
  52.     //
  53.     TEditFile(TWindow*   parent,
  54.               int        resourceId,
  55.               TModule&   module);
  56.    ~TEditFile();
  57.  
  58.     virtual bool  CanClear();
  59.     virtual bool  CanClose();
  60.  
  61.     virtual void  NewFile();      
  62.     virtual void  Open();         
  63.     virtual bool  Read(const char far* fileName = 0);
  64.     virtual void  ReplaceWith(const char far* fileName); 
  65.     virtual bool  Save();         
  66.     virtual bool  SaveAs();       
  67.     virtual bool  Write(const char far* fileName=0);
  68.  
  69.     const char far* GetFileName() const;
  70.     void          SetFileName(const char far* fileName);
  71.  
  72.     TOpenSaveDialog::TData& GetFileData();
  73.     void   SetFileData(const TOpenSaveDialog::TData& fd);
  74.  
  75.   protected:  
  76.  
  77.     // Command response functions
  78.     //
  79.     void          CmFileNew();     // CM_FILENEW
  80.     void          CmFileOpen();    // CM_FILEOPEN
  81.     void          CmFileSave();    // CM_FILESAVE
  82.     void          CmFileSaveAs();  // CM_FILESAVEAS
  83.  
  84.     // Command enabler functions
  85.     //
  86.     void          CmSaveEnable(TCommandEnabler& commandHandler);
  87.  
  88.   protected:
  89.     // Override virtual functions defined by TWindow
  90.     //
  91.     void          SetupWindow();
  92.  
  93.   public_data:
  94.     TOpenSaveDialog::TData FileData;
  95.     char far* FileName;
  96.  
  97.   private:
  98.     // Hidden to prevent accidental copying or assignment
  99.     //
  100.     TEditFile(const TEditFile&);
  101.     TEditFile& operator =(const TEditFile&);
  102.  
  103.   DECLARE_RESPONSE_TABLE(TEditFile);
  104.   DECLARE_STREAMABLE(_OWLCLASS, TEditFile, 1);
  105. };
  106.  
  107. // Generic definitions/compiler options (eg. alignment) following the 
  108. // definition of classes
  109. #include <services/posclass.h>
  110.  
  111. #if defined(BI_NAMESPACE)
  112. } // namespace OWL
  113. #endif
  114.  
  115. //----------------------------------------------------------------------------
  116. // Inline implementations
  117. //
  118.  
  119. //
  120. inline
  121. TEditFile::TEditFile(TWindow* parent, int resourceId, TModule& module)
  122.           :TEditSearch(parent, resourceId, module),
  123.            FileName(0)
  124. {
  125. }
  126.  
  127. // Return the filename for this buffer.
  128. //
  129. inline const char far* TEditFile::GetFileName() const {
  130.   return FileName;
  131. }
  132.  
  133. //
  134. // Return the FileData data member used for the common dialogs.
  135. //
  136. inline TOpenSaveDialog::TData& TEditFile::GetFileData() {
  137.   return FileData;
  138. }
  139.  
  140. //
  141. inline void TEditFile::SetFileData(const TOpenSaveDialog::TData& fd) {
  142.   FileData = fd;
  143. }
  144.  
  145. //
  146. inline void TEditFile::CmFileNew() {
  147.   NewFile();
  148. }
  149.  
  150. //
  151. inline void TEditFile::CmFileOpen() {
  152.   Open();
  153. }
  154.  
  155. //
  156. inline void TEditFile::CmFileSave() {
  157.   Save();
  158. }
  159.  
  160. //
  161. inline void TEditFile::CmFileSaveAs() {
  162.   SaveAs();
  163. }
  164.  
  165.  
  166. #endif  // OWL_EDITFILE_H
  167.